package com.example.leetcode.prcatice;

public class MyTest {


    public ListNode reverse(ListNode head){
        ListNode pre = null;
        ListNode now = head;
        while (now != null){
            ListNode next = now.next;
            now.next = pre;
            pre = now;
            now = next;
        }
        return pre;
    }
}



class Demo{
    public static void main(String[] args) {
        ListNode head = new ListNode(1);
        head.next = new ListNode(2);
        head.next.next = new ListNode(3);
        head.next.next.next = new ListNode(4);
        head.next.next.next.next = new ListNode(5);
        MyTest m = new MyTest();
        ListNode reverse = m.reverse(head);
        while (reverse != null){
            System.out.print(reverse.val+" ");
            reverse = reverse.next;
        }
    }
}